home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2266 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.5 KB  |  94 lines

  1. Path: uni-duisburg.de!news
  2. From: mauch@uni-duisburg.de (Michael Mauch)
  3. Newsgroups: comp.lang.c++,comp.os.msdos.programmer
  4. Subject: Re: 'interrupt' in Turbo C++
  5. Date: Tue, 16 Jan 1996 21:31:34 +0100
  6. Organization: Gesamthochschule Duisburg
  7. Message-ID: <30faf82f.750220@news.uni-duisburg.de>
  8. References: <4d4p12$67h@fang.dsto.defence.gov.au>
  9. NNTP-Posting-Host: slip12.uni-duisburg.de
  10. X-Newsreader: Forte Agent .99c/16.141
  11.  
  12. Hi!
  13.  
  14. dpr@itd.dsto.gov.au (David Rajaratnam) wrote:
  15.  
  16. > Hi there,
  17. > I hope I've got the right newsgroups for this question. 
  18. > I'm having problems writing an interrupt handler using 
  19. > Borland Turbo C++ v3 for DOS. The problem arises when 
  20. > I want the interrupt function to return results via 
  21. > the registers.
  22. > Under C what I do is;
  23. > typedef struct {
  24. >     int bp, di, si, ds, es, dx, cx, bx, ax, ip, cs, fl;
  25. > } IREGS;
  26. > static void interrupt (*mycinterrupt)(IREGS ir){
  27. >     
  28. >     <do stuff>
  29. >     
  30. >     ir.ax = _AX
  31. > }
  32. [...]
  33. > Unfortunately, the declaration of setvect and getvect in C++ 
  34. > does things a bit differently. I quote;
  35. >   Syntax
  36. >   void interrupt(*getvect(int interruptno))();                 /*C version*/
  37. >   void interrupt(*getvect(int interruptno))(...);            //C++ version
  38. >   void setvect(int interruptno, void interrupt (*isr)());    /*C version*/
  39. >   void setvect(int interruptno, void interrupt (*isr)(...)); //C++ version
  40. > So making the call setvect(0xXX, mycinterrupt) will give me a 
  41. > compiler error now. To get around this what I tried to do was;
  42. > static void interrupt (*mycppinterrupt)(...){
  43. >     IREGS *ir;
  44. >     <do stuff>
  45. >     ir = (IREGS *)...;
  46. >     ir->ax = _AX;
  47. > }
  48. > Although this version compilied, when run the results where 
  49. > not what I was hoping for. I also tried using the <stdarg.h>
  50. > stuff but they gave me the same results as above. I can only
  51. > guess that what C++ expects to see is different to the
  52. > C version. Unfortunately nowhere in the Documentation (that
  53. > I can find), or other books I own, does it describe what 
  54. > C++ expects. Mind you the arguments of the C version were
  55. > not adequately described either, it's just that I happened
  56. > to come across an example that used the 
  57. > tydef struct { bp, ...} IREGS method.  
  58.  
  59.  
  60. typedef struct
  61. {
  62.     int bp, di, si, ds, es, dx, cx, bx, ax, ip, cs, fl;
  63. } IREGS;
  64.  
  65.  
  66. #ifdef __cplusplus
  67. typedef void interrupt (*ISR_t)(...);
  68. #else
  69. typedef void interrupt (*ISR_t)(IREGS iregs);
  70. #endif
  71.  
  72. void far interrupt NewIntHandler(IREGS iregs)
  73. {
  74.   <do_stuff>  
  75. }
  76.  
  77. setvect(IntNum,(ISR_t)NewIntHandler);
  78. // will work in C and C++ now
  79.  
  80. Hope this helps...
  81.             Michael
  82.  
  83.